package com.banyuan;

import javax.swing.*;

public class Test {
    public static void main(String[] args) {
        int a = 5;
        int b = 2;
        int c = 8;
        int x = (a > b ? (a > c ? a : c) : (b > c ? b : c));
        System.out.println("最大值是：" + x);

        //用冒泡算法排序
        int y = 0;

        //冒泡算法的第一轮排序
        //c的值变为最大值

        if (a > b) {
            y = a;
            a = b;
            b = y;
        }
        if (b > c) {
            y = b;
            b = c;
            c = y;
        }

        //冒泡算法的第二轮排序
        //比较ab的两个值的大小
        if (a > b) {
            y = a;
            a = b;
            b = y;
        }
        System.out.println("" + a + b + c);

        //计算5的阶乘
        int ii = 1;
        for (int i = 1; i <= 5; i++) {
            ii *= i;
        }

        System.out.println(ii);

        //如果n比100大，则疯狂自减，如果比100小，则疯狂自增，直到等于100

        int n = 50;
        for (; n != 100; ) {
            if (n < 100) {
                n++;
            } else if (n > 100) {
                n--;
            }
        }
        System.out.println(n);

        //打印某个数所有的因子
        int m = 6;
        for (int i = 1; i <= m; i++) {
            if (m % i == 0) {
                System.out.print(i + " ");
            }

        }

        System.out.println();

        //计算1000以内的完全数
        for (int i = 1; i <= 1000; i++) {
            int sum = 0;
            for (int j = 1; j <= i / 2; j++) {
                if (i % j == 0) {
                    sum += j;
                }
            }
            if (sum == i) {
                System.out.println(i);
            }
        }

        //判断一个数是不是素数
        int q = 7; int count = 0;
        for (int i = 2; i <= q/2 ; i++) {
            if(q % i == 0){
                count++;
            }
        }
        if (count == 0){
            System.out.println(q + "是素数");
        }else{
            System.out.println(q + "不是素数");
        }

    }

}

